(function($){
	var get_company = function(){
		$.getJSON("/get_company/", {'id': $("#id_company").val()}, function(data){
			if(data.len == '1'){
				var html = "<option value=''>---------</option>";
				html += "<option selected='selected' value='" + data.data[0].id + "'>" + data.data[0].name + "</option>";
				$("#id_company").html(html);
			}
			else{
	    		var html = "<option value=''>---------</option>";
	    		$.each(data.data, function(k, v){
	    			if(v.id == $("#id_company").val()){
	    				
	    				html += "<option selected='selected' value='" + v.id + "'>" + v.name + "</option>";
	    			}else{
		    			html += "<option value='" + v.id + "'>" + v.name + "</option>";
	    			}
	    		});
	    		$("#id_company").html(html);
	    	}
    	});
	}

	$(document).ready(function(){
		get_company();
	});
})(django.jQuery);
